package com.fc.happyteam.job;

import org.quartz.ee.servlet.QuartzInitializerListener;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;

/**
 * 由于本框架数据库采用自动增量创建，在首次启动时Quartz相关表尚未创建，启动会出错。暂时注掉了这些程序。如果您需要使用Quartz
 * 任务，等首次启动成功后再放开注释即可正常使用。您也可以使用SpringBoot自带的计划任务，参考SpringScheduleTask。
 * NOTE: As the Quartz Job Configuration requires database schema. And Happyteam using auto increamental db migration.
 * The Quartz relative tables has not been created yet.
 * Comment out here in case bring up server failed first time.
 * Release the comments when you want use Quartz schedule job after DB schema created by DBMigration process.
 * Alternatively, you can use SpringBoot scheduling job as well, Refer to SpringScheduleTask.
 */
@Configuration
public class SchedulerConfig {
//
//    @Bean
//    public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) throws IOException {
//        SchedulerFactoryBean factory = new SchedulerFactoryBean();
//        factory.setQuartzProperties(quartzProperties());
//        return factory;
//    }
//
//    @Bean
//    public Properties quartzProperties() throws IOException {
//        PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
//        propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
//        return propertiesFactoryBean.getObject();
//    }
//
//    @Bean
//    public QuartzInitializerListener executorListener() {
//        return new QuartzInitializerListener();
//    }
//
//    @Bean
//    public SchedulePreProcessor scheduleProcessor() {
//        return new SchedulePreProcessor();
//    }
}
